package com.zy.common.core.exception;

import com.zy.common.core.R;
import com.zy.common.core.enums.BaseEnum;
import com.zy.common.core.enums.ErrorEnums;

/**
 * 业务异常类
 * 记录error级别日志
 *
 * @author zy
 * @since 2023/3/13 15:40
 */
public class BizException extends RuntimeException {

    private Integer code;

    public BizException(R r) {
        this(r.getCode(), r.getMsg(), null);
    }

    public BizException(R r, Throwable cause) {
        this(r.getCode(), r.getMsg(), cause);
    }

    public BizException(R r, String message) {
        this(r.getCode(), message, null);
    }

    public BizException(R r, String message, Throwable cause) {
        this(r.getCode(), message, cause);
    }

    public BizException(Integer code, String message) {
        this(code, message, null);
    }

    public BizException(Integer code, String message, Throwable cause) {
        super(message, cause);
        this.code = code;
    }

    public BizException(BaseEnum errorEnums) {
        this(errorEnums.getCode(), errorEnums.getDesc(), null);
    }

    public Integer getCode() {
        return code;
    }

    public BizException(Throwable e) {
        super(e.getMessage(), e);
    }
}
